package com.guochenglang.www.service.impl;

import com.guochenglang.www.dao.UserDao;
import com.guochenglang.www.pojo.User;
import com.guochenglang.www.service.LogInService;
import com.guochenglang.www.util.Encryption;
import com.guochenglang.www.util.MyDependency;

import java.lang.reflect.InvocationTargetException;
import java.security.NoSuchAlgorithmException;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 * 登录业务
 *
 * @author 郭程朗
 */
public class LogInServiceImpl implements LogInService {
    public LogInServiceImpl() {
    }

    /**
     * 登录
     *
     * @param user 登录信息
     * @return 用户
     */
    @Override
    public User logIn(User user) throws SQLException, IllegalAccessException, InstantiationException, InterruptedException, NoSuchAlgorithmException {
        //加密密码
        user.setPassword(Encryption.encryption(user.getPassword()));
        ArrayList<User> select = MyDependency.returnObject(UserDao.class).userSelect(user);
        if (select.isEmpty()) {
            return null;
        }
        return select.get(0);
    }
}
